package com.atguigu.controller;

import com.atguigu.entities.CommonResult;
import com.atguigu.entities.Payment;
import com.atguigu.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
public class PaymentController {

    @Autowired
    private PaymentService service;

    @RequestMapping(value = "/payment/create")
    public CommonResult create(@RequestBody Payment payment){
        int result = service.create(payment);
        log.info("-------------插入结果-----------"+result);

        if (result > 0){
            return new CommonResult(200,"数据插入成功",result);
        }else {
            return new CommonResult(500,"数据插入错误",result);
        }
    }

    @RequestMapping(value = "/payment/get/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") long id){
        Payment payment = service.getPaymentById(id);
        log.info("-------------查询结果-----------"+payment);

        if (payment!=null){
            return new CommonResult(200,"数据查询成功",payment);
        }else {
            return new CommonResult(500,"数据查询错误",null);
        }
    }



}
